﻿using System;
using System.Globalization;
using System.Threading;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media.Imaging;
using UniversalEditor.Base.Utils.LoggerModule;

namespace UniversalEditor.Base.Utils.Converters
{
	public class PathToImageConverter : IValueConverter
	{
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			string path = value as string;

			if (string.IsNullOrEmpty(path))
				return null;

			return new Image {Source = new BitmapImage(new Uri(path, UriKind.RelativeOrAbsolute))};
		}

		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			return null;
		}
	}

	public class ExtensionToImageSourceConverter : IValueConverter
	{
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			string path = value as string;

			if (string.IsNullOrEmpty(path))
				return null;

			return IconReader.GetFileIcon(path, IconReader.IconSize.Small, false).ToImageSource();
		}

		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			return null;
		}
	}
}
